import { request } from "@umijs/max";

// 获取图书列表
export async function getBooks(params?: any) {
  const res = await request('/books/', { params });
  return res
}

// 获取图书详情
export async function getBookDetail(id: number) {
  return await request(`/books/${id}/`);
}

// 创建图书
export async function createBook(data: any) {
  return await request('/books/', { method: 'POST', data });
}

// 更新图书
export async function updateBook(id: number, data: any) {
  return await request(`/books/${id}/`, { method: 'PUT', data });
}

// 删除图书
export async function deleteBook(id: number) {
  return await request(`/books/${id}/`, { method: 'delete' });
}

// 搜索图书
export async function searchBooks(query: string) {
  return await request(`/books/search/?q=${query}`);
}

// 借阅图书
export async function borrowBook(id: number) {
  return await request(`/books/${id}/borrow/`, { method: 'POST' });
}

// 归还图书
export async function returnBook(id: number) {
  return await request(`/books/${id}/return_book/`, { method: 'POST' });
}